extends Node

class_name turnCheck

onready var TurnOver = preload("res://ui/TurnOver.tscn")
var curTurn:bool
signal turnAnimationFinish

func checkTurnOver(main) -> bool:
	var players = main.players
	var enemys = main.enemys
	var turns = main.turns
	var curTurn = main.curTurn
	## 当前是玩家回合
	if curTurn:
		var allOver = true
		for actor in players:
			if !actor.finish:
				allOver = false
				break
		if allOver:
			curTurn = false
			showTurnOver(curTurn)
			yield(self, "turnAnimationFinish")
	else:
		var allOver = true
		for enemy in enemys:
			if !enemy.finish:
				allOver = false
				break
		if allOver:
			curTurn = true
			showTurnOver(curTurn)
			yield(self, "turnAnimationFinish")
	return curTurn

func showTurnOver(curTurn):
	var turnOver = TurnOver.instance()
	get_parent().add_child(turnOver)
	turnOver.showTurn(curTurn)
	yield(turnOver, "finish")
	turnOver.queue_free()
	emit_signal("turnAnimationFinish")
